
<!--
    用户申请恢复管理页面
 -->
 <template>
  <div>
      <div style="margin:10px 0;">
                  <el-input v-model="sousuofrom.userName" style="width:200px;" placeholder="请输入昵称" suffix-icon="el-icon-message" class="ml-5"></el-input>
                  <el-button @click="load()" class="ml-5" type="primary">搜索</el-button>
                  <el-button @click="reset()" style="margin-left: 5px;" type="warning">重置</el-button>
      </div>
          <!-- 表格数据 -->
              <el-table :data="tableData" border stripe header-cell-class-name="headerBg">
                  <el-table-column type="selection" width="55" />
                  <el-table-column prop="userName" label="用户名" width="120" />
                  <el-table-column prop="imageId" label="用户头像" width="120">
                    <template slot-scope="scope">
                      <el-image
                        style="width: 100px; height: 100px"
                        :src="$imageUrl + scope.row.imageId"></el-image>
                    </template>
                  </el-table-column>
                  <el-table-column prop="applicationStatus" label="申请状态" width="160">
                    <template slot-scope="scope">
                      {{scope.row.applicationStatus==1?"已处理":scope.row.applicationStatus==2?"未处理":""}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="processingResult" label="处理结果" width="160">
                    <template slot-scope="scope">
                      {{scope.row.processingResult==0?"待审核":scope.row.processingResult==2?"已通过":scope.row.processingResult==1?"驳回":""}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="applicationTime" label="申请时间" width="120" />
                  <el-table-column prop="processingTime" label="处理时间" width="120" />
                  <el-table-column label="操作" width="300">
                    <template slot-scope="scope">
                      <el-button type="warning" @click="delPhysicianInfo(scope.row.restoreId)">通过<i class="el-icon-edit"></i></el-button>
                      <el-button type="warning" @click="userDelete(scope.row)">驳回<i class="el-icon-edit"></i></el-button>
                    </template>
                  </el-table-column>
              </el-table>
              <el-dialog
              :title=title
              :visible.sync="reporeView"
              width="40%"
              center>
              <el-form :model="updateForm" ref="updateForm">
                <el-form-item label="驳回原因" prop="rejectionReason" >
                  <el-input v-model="updateForm.rejectionReason" auto-complete="off"></el-input>
                </el-form-item>
              </el-form>
              <span slot="footer" class="dialog-footer">
                <el-button @click="ReporeView = false">取 消</el-button>
                <el-button type="primary" @click="update('updateForm')">确 定</el-button
                >
              </span>
          </el-dialog>
          <!-- 分页 -->
              <div style="padding:10px 0;">
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage4"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="5"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total" style="margin-top: 20px;">
              </el-pagination>
            </div>
  </div>
</template>

<script>
// import  request  from '@/utils/request.js'

export default {
  data () {
    return {
      title: '',
      reporeView: false,
      currentPage4: 1, // 第几页
      // 表格数据
      tableData: [],
      // multipleSelection:[],
      pageNum: 1, // 一条一条的走 条数
      pageSize: 5, // 一页五条页数
      total: 0,
      avatarUrl: '',
      updateForm: {
        id: '',
        processingResult: '',
        restoreId: '',
        rejectionReason: ''
      },
      // 模糊查搜索框数值
      sousuofrom: {
        userName: ''
      },
      rules: {
        nickname: [
          { required: true, message: '请输入昵称', trigger: 'blur' },
          { min: 1, max: 6, message: '长度在 1 到 6个字符', trigger: 'blur' }
        ]
      }
    }// return
  },
  mounted () {
    this.load()
  },
  // 方法集合
  methods: {
    userDelete (row) {
      this.title = '驳回原因'
      this.reporeView = true
      this.updateForm = JSON.parse(JSON.stringify(row))
    },
    load () { // 查询申请恢复的账号信息
      this.$axios.get('/cancel/cancelList',
        {
          params: {
            userName: this.sousuofrom.userName,
            pageNum: this.pageNum,
            pageSize: this.pageSize
          }
        }).then(res => {
        this.tableData = res.data.data.content
        this.total = res.data.data.totalSize
      }).catch(err => {
      })
    },

    delPhysicianInfo (restoreId) { // 点击恢复账号信息
      this.$axios.delete('/cancel/restoreUpdate/' + restoreId).then(res => {
        if (res.data.code === 200) {
          this.$message.success('恢复成功')
          this.load()
        } else {
          this.$message.error('注销失败')
        }
      })
    },

    update (row) { // 驳回
      this.$axios.post('/cancel/recoverReason', {
        restoreId: this.updateForm.restoreId,
        rejectionReason: this.updateForm.rejectionReason
      }).then((res) => {
        if (res.data.flag) {
          this.myMessage('success', '操作成功') // 添加或修改成功提示
          this.reporeView = false // 关闭窗口
          this.load()
        } else {
          this.myMessage('warning', res.data.code)
        }
      }).catch((err) => {
        this.myMessage('warning', '对不起，保存失败，请您稍后再试！') // 添加或修改失败
      })
    },

    // // 彻底删除注销的用户
    // userDelete (id) { //
    //   this.$confirm('此操作将注销用户彻底删除, 是否继续?', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     this.$axios.delete('/user/userDelete', {
    //       params: {
    //         id: id
    //       }
    //     }).then(res => {
    //       if (res.data.code === 200) {
    //         this.myMessage('success', '删除成功')
    //         this.load()
    //       } else {
    //         this.myMessage('warning', '删除失败')
    //       }
    //     }).catch(res => {
    //       this.myMessage('error', '删除失败，请联系管理员')
    //     })
    //   }).catch(res => {
    //     this.myMessage('info', '已取消删除')
    //   })
    // },
    myMessage (type, message) {
      this.$message({
        message: message,
        type: type
      })
    },
    handleSizeChange (val) { // 改变每页条数
      this.pageSize = val
      this.load()
    },
    handleCurrentChange (val) { // 改变当前页
      this.pageNum = val
      this.load()
    }
  }

}
</script>

<style scoped>
html,body,div{
  margin: 0;
  padding: 0;
  text-align: left;
}
html.body{
  height: 100%;
}
/* *{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
} */
.ml-5{
  margin-left: 5px;

}
.mr-5{
  margin-right: 5px;
}
.pd-10{
  padding: 10px 0;
}
</style>
